PREFIX = 
SRC = 
TESTS = 
CC = gcc
CXX = g++
LD = g++
CFLAGS = 
LDFLAGS = 
LTFLAGS = 
LTENV = 
LIBTOOL = libtool
LIB = bncsutil
OBJS = build/bsha1.o build/cdkeydecoder.o build/checkrevision.o \
build/decodekey.o build/file.o build/hashtable.o build/libinfo.o \
build/nls.o build/oldauth.o build/pe.o build/sha1.o build/stack.o \
build/debug.o
LTOBJS = build/bsha1.lo build/cdkeydecoder.lo build/checkrevision.lo \
build/decodekey.lo build/file.lo build/hashtable.lo build/libinfo.lo \
build/nls.lo build/oldauth.lo build/pe.lo build/sha1.lo build/stack.lo \
build/debug.lo
COMMON = $(SRC)/mutil.h $(SRC)/mutil_types.h $(SRC)/bncsutil.h
HEADERS = bncsutil.h bsha1.h cdkeydecoder.h checkrevision.h debug.h \
decodekey.h file.h hashtable.h keytables.h libinfo.h mutil.h mutil_types.h \
nls.h oldauth.h pe.h sha1.h stack.h
RM = rm

all: build/$(LIB).la

install: build/$(LIB).la
	libtool --mode=install install -c build/lib$(LIB).la $(PREFIX)/lib/lib$(LIB).la
	install -m 755 -d $(PREFIX)/include/bncsutil
	for header in $(HEADERS); do install -m 644 $(SRC)/$$header $(PREFIX)/include/bncsutil/$$header; done

rebuild: clean all

build/$(LIB).la: $(OBJS)
	$(LTENV) $(LIBTOOL) --tag=CXX --mode=link $(LD) $(LDFLAGS) -o build/lib$(LIB).la $(LTOBJS) -lgmp $(LTFLAGS)

build/bsha1.o: $(SRC)/bsha1.cpp $(SRC)/bsha1.h $(COMMON)
	$(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(CFLAGS) -c -o build/bsha1.lo $(SRC)/bsha1.cpp
	
build/cdkeydecoder.o: $(SRC)/cdkeydecoder.cpp $(SRC)/cdkeydecoder.h $(COMMON)
	$(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(CFLAGS) -c -o build/cdkeydecoder.lo $(SRC)/cdkeydecoder.cpp

build/checkrevision.o: $(SRC)/checkrevision.cpp $(SRC)/checkrevision.h $(COMMON)
	$(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(CFLAGS) -c -o build/checkrevision.lo $(SRC)/checkrevision.cpp

build/decodekey.o: $(SRC)/decodekey.cpp $(SRC)/decodekey.h $(COMMON)
	$(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(CFLAGS) -c -o build/decodekey.lo $(SRC)/decodekey.cpp

build/file.o: $(SRC)/file.c $(SRC)/file.h $(COMMON)
	$(LIBTOOL) --tag=C --mode=compile $(CC) $(CFLAGS) -c -o build/file.lo $(SRC)/file.c

build/hashtable.o: $(SRC)/hashtable.c $(SRC)/hashtable.h $(COMMON)
	$(LIBTOOL) --tag=C --mode=compile $(CC) $(CFLAGS) -c -o build/hashtable.lo $(SRC)/hashtable.c

build/libinfo.o: $(SRC)/libinfo.cpp $(SRC)/libinfo.h $(COMMON)
	$(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(CFLAGS) -c -o build/libinfo.lo $(SRC)/libinfo.cpp

build/nls.o: $(SRC)/nls.c $(SRC)/nls.h $(COMMON)
	$(LIBTOOL) --tag=C --mode=compile $(CC) $(CFLAGS) -c -o build/nls.lo $(SRC)/nls.c

build/oldauth.o: $(SRC)/oldauth.cpp $(SRC)/oldauth.h $(COMMON)
	$(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(CFLAGS) -c -o build/oldauth.lo $(SRC)/oldauth.cpp

build/pe.o: $(SRC)/pe.c $(SRC)/pe.h $(COMMON)
	$(LIBTOOL) --tag=C --mode=compile $(CC) $(CFLAGS) -c -o build/pe.lo $(SRC)/pe.c

build/sha1.o: $(SRC)/sha1.c $(SRC)/sha1.h $(COMMON)
	$(LIBTOOL) --tag=C --mode=compile $(CC) $(CFLAGS) -c -o build/sha1.lo $(SRC)/sha1.c

build/stack.o: $(SRC)/stack.c $(SRC)/stack.h $(COMMON)
	$(LIBTOOL) --tag=C --mode=compile $(CC) $(CFLAGS) -c -o build/stack.lo $(SRC)/stack.c

build/debug.o: $(SRC)/debug.c $(SRC)/debug.h $(COMMON)
	$(LIBTOOL) --tag=C --mode=compile $(CC) $(CFLAGS) -c -o build/debug.lo $(SRC)/debug.c

clean:
	for i in $(OBJS) $(LTOBJS); do $(RM) "$$i"; done
